#!/usr/bin/env python3
# -*- coding: utf-8 -*-

__author__ = 'Xinrui Wang'

from datetime import datetime
import time

class Eclipse(object):
    def set_info(self):
        Eclipse.chukui = {'Wuhan': datetime(2020, 6, 21, 14, 30, 37), 'Beijing': datetime(2020, 6, 21, 14, 33, 24), 'Shanghai': datetime(2020, 6, 21, 14, 45, 33), 'Xiamen': datetime(2020, 6, 21, 14, 43, 36)}
        Eclipse.shishen = {'Wuhan': datetime(2020, 6, 21, 15, 59, 20), 'Beijing': datetime(2020, 6, 21, 15, 50, 18), 'Shanghai': datetime(2020, 6, 21, 16, 6, 18), 'Xiamen': datetime(2020, 6, 21, 16, 10, 47)}
        Eclipse.fuyuan = {'Wuhan': datetime(2020, 6, 21, 17, 15, 9), 'Beijing': datetime(2020, 6, 21, 16, 58, 45), 'Shanghai': datetime(2020, 6, 21, 17, 16, 4), 'Xiamen': datetime(2020, 6, 21, 17, 24, 15)}

    def take_out(self, city, name):
        if name == 'chukui':
            return Eclipse.chukui[city]
        elif name == 'shishen':
            return Eclipse.shishen[city]
        else:
            return Eclipse.fuyuan[city]

class Io(object):
    def set_city(self, city):
        Io.city = city

    def take_out(self, name):
        return Eclipse().take_out(Io.city, name)

    def countdown(self, name):
        Io.dt_eclipse = Io().take_out(name).timestamp()
        Io.dt_now = datetime.now().timestamp()
        Io.output = Io.dt_eclipse - Io.dt_now
        return Io.output

    def output_countdown(self, name):
        while True:
            output = Io().countdown(name)
            if output < 1:
                print('\n时间到')
                break
            print(output)

Eclipse().set_info()
city = input('\n城市英文名（开头大写）: ')
Io().set_city(city)

while True:
    print('\n1.输出初亏时间 2.输出食甚时间 3.输出复圆时间 数字后加c表示倒计时 4.退出')
    choice = input('选择: ')

    if choice == '1' or choice == '2' or choice == '3' or choice == '4':
        if choice == '1':
            print(Io().take_out('chukui'))
        elif choice == '2':
            print(Io().take_out('shishen'))
        elif choice == '3':
            print(Io().take_out('fuyuan'))
        else:
            print('\n再见')
            time.sleep(2)
            exit()

    else:
        if choice == '1c':
            Io().output_countdown('chukui')
        if choice == '2c':
            Io().output_countdown('shishen')
        else:
            Io().output_countdown('fuyuan')
